package com.lx.yygh.hosp.api;

import com.lx.yygh.common.result.Result;
import com.lx.yygh.hosp.service.DepartmentService;
import com.lx.yygh.hosp.service.HospitalService;
import com.lx.yygh.hosp.service.ScheduleService;
import com.lx.yygh.model.hosp.Hospital;
import com.lx.yygh.model.hosp.Schedule;
import com.lx.yygh.vo.hosp.DepartmentVo;
import com.lx.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.scheduling.annotation.Schedules;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author c先生
 * @date 2022年10月19日 下午 4:05:39
 * @describe
 */
@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital2")
public class HospitalApi2Controller {
    @Resource
    private HospitalService hospitalService;
    @Resource
    private DepartmentService departmentService;
    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation(value = "获取分页列表")
    @GetMapping("/list/{page}/{limit}")
    public Result list(@PathVariable("page") Integer page ,
                       @PathVariable("limit")Integer limit,
                       HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitalPage = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitalPage);
    }

    @ApiOperation(value = "根据医院名字模糊查询医院")
    @GetMapping("/getByHosname/{queryString}")
    public Result list(@PathVariable("queryString")String queryString){
        List<Hospital> hospitalList = hospitalService.getByHosname(queryString);
        return Result.ok(hospitalList);
    }

    @ApiOperation(value = "根据hoscode查询医院的详细信息")
    @GetMapping("/show/{hoscode}")
    public Result showHospitalDetailByHoscode(@PathVariable("hoscode")String hoscode){
        Hospital hospital = hospitalService.getHospitalByHoscode(hoscode);
        return Result.ok(hospital);
    }

    @ApiOperation(value = "根据hoscode查询医院科室信息")
    @GetMapping("/findDepartment/{hoscode}")
    public Result findDepartment(@PathVariable("hoscode")String hoscode){
        List<DepartmentVo> deptDataTree = departmentService.findDeptDataTree(hoscode);
        return Result.ok(deptDataTree);
    }

    @ApiOperation(value = "根据医院和部门的code获取可以预约的排班数据")
    @GetMapping("/auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingScheduleRule(@PathVariable("page")Integer page,
                                         @PathVariable("limit")Integer limit,
                                         @PathVariable("hoscode")String hoscode,
                                         @PathVariable("depcode")String depcode){
        Map<String, Object> map = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return Result.ok(map);
    }

    @GetMapping("/auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(@PathVariable("hoscode")String hoscode,
                                   @PathVariable("depcode")String depcode,
                                   @PathVariable("workDate")String workDate){
        List<Schedule> scheduleDetail = scheduleService.getScheduleDetail(hoscode, depcode, workDate);
        return Result.ok(scheduleDetail);
    }

    @ApiOperation(value = "根据排班id获取排班信息")
    @GetMapping("/getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable("scheduleId")String scheduleId){
        Schedule schedule = scheduleService.getScheduleById(scheduleId);
        return Result.ok(schedule);
    }
}
